import { contextBridge, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'

const api = {}
const renderApi = {
  minWin: (paramsUrl): void => ipcRenderer.send('minWindow', paramsUrl),
  scaleWin: (paramsUrl): void => ipcRenderer.send('scaleWindow', paramsUrl),
  closeWin: (paramsUrl): void => ipcRenderer.send('closeWindow', paramsUrl),
  openWin: (item): void => ipcRenderer.send('openWin', item)
}
if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronAPI)
    contextBridge.exposeInMainWorld('api', api)
    contextBridge.exposeInMainWorld('renderAPI', renderApi)
  } catch (error) {
    console.error(error)
  }
} else {
  // @ts-ignore (define in dts)
  window.electron = electronAPI
  // @ts-ignore (define in dts)
  window.api = api
}
